// pages/mypet/index.js
const app=getApp()

Page({

    data: {
      petInfos:"",
    },
   onLoad: function (options) {
      var that = this;
      //console.log(data.datas);

      that.getPetInfo()
    },

    getPetInfo(){
      var that = this
      
      wx.request({
        url: app.globalData.prefixUrl + '/chong/pet/pet/user/' + app.globalData.userId,
        method:"GET",
        success(e){
          console.log("user pet: ", e)
          // 设置宠物data
          that.setData({
            petInfos: e.data
          })
        },
        fail(e){
          console.log("获取宠物数据失败: ", e)
        }
      })
    },

      // 下拉刷新
  onPullDownRefresh: function() {
    console.log("下拉刷新")
    var that = this;
    wx.showNavigationBarLoading()

    that.getPetInfo()

    setTimeout(() => {
      wx.hideNavigationBarLoading()
      wx.stopPullDownRefresh()
    }, 1000)
  },

  toCheckedPet: function(e) {
    var that = this
    let petId = e.currentTarget.id
    let petIndex = e.currentTarget.dataset.index
    // if (!petId == "") {
      console.log("pet ididid: ", petId)
      console.log("pet indexindex: ", petIndex)
      wx.navigateTo({
        url: "../petItem/index?petId=" + petId +"&petIndex=" +petIndex
      })
      console.log(e)
    // } else {
      // console.log("无内容")
    // }
  },

    addPet(){
      var that = this
        wx.navigateTo({
          url: '/pages/mine/pet/addPet/index?arrayLength=' +that.data.petInfos.length,
        })
    },

})